package com.amigo.online.provider.adv.mapper;

import java.util.List;
import java.util.Set;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.amigo.online.common.param.result.AdvRecommendInfo;

@Mapper
public interface AdvRecommendSourceMapper {

    @Select({" <script>"
            + "select v.id, b.adv_id as advId, b.video_url as video, b.video_img_url as cover, b.video_watermark_url as waterMarkVideo,"
            + " b.music_url as advMusicUrl, b.music_name as advMusicName, b.user_name as advUserName, b.user_avatar as advUserAvatarUrl,"
            + " b.content as content, v.up as up, v.share as share, v.comment as comment, b.ios_click_feedback as iosType,"
            + " b.android_click_feedback as androidType, b.android_forward_url as androidWebUrl, b.ios_forward_url as iosWebUrl,"
            + " b.ios_app_url as iosAppUrl, b.android_app_url as androidAppUrl, a.width, a.height from adv_recommend_source_tbl a, adv_recommend_video_tbl b,"
            + " video_tbl v where v.id = b.video_id and a.adv_id = b.adv_id and v.ads = 1 and a.adv_id in "
            + " <foreach collection='advIds' item='advId' open='(' close=')' separator=','>"
            + "	#{advId}"
            + "	</foreach>"
            + " and abs(ratio - #{ratio}) = (select min(abs(ratio - #{ratio})) from adv_recommend_source_tbl where adv_id = a.adv_id )"
            + "	</script>"})
    List<AdvRecommendInfo> getAdvSourceBySizeAndIds(@Param("ratio") double ratio, @Param("advIds") Set<Integer> advSet);

}
